package com.zl.rbac.entity;/**
 * @author suke
 * @create 2021-01-07 14:28
 */

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *  用户类
 * @ClassName: User
 * @author: suke
 * @since: 2021/1/7 14:28
 */
@Data
@TableName("tb_user")
public class User extends BaseEntity implements Serializable {
    private static final long serialVersionUID = -2718662794916257657L;
    private String  username;
    private String  password;
    private Boolean admin;
    @TableField("isdeleted")  //Mybatis-plus 对驼峰命名法的属性 对应列名:  is_deleted
    private Boolean isDeleted;

    @TableField(exist = false)  //表示该属性不是数据库的列
    private List<Role> roleList = new ArrayList<>();


    //user.password  调用getPassword()
   /* public String getPassword(){
        return "******";
    }*/

    public String getRoleNames(){
        if(this.admin){  //管理员
            return "[管理员]";
        }else{
            if(roleList!=null && roleList.size()>0) {
                //[角色1,角色2,角色3]
                StringBuffer sb = new StringBuffer();
                sb.append("[");
                for (Role role : roleList) {
                    sb.append(role.getName() + ",");
                }
                //删除最后一个逗号
                sb.deleteCharAt(sb.length() - 1);
                sb.append("]");
                return sb.toString();
            }
            //表示这个用户没有分配角色
            return "[]";
        }

    }

}
